from collections import Counter
class Solution:
    def countLargestGroup(self, n: int) -> int:
        def get_sum(num):
            ans = 0
            s = 0
            while num != 0:
                num,b = divmod(num, 10)
                ans +=b * (10 ** s)
            return ans
        c = Counter()
        for i in range(1, n+1):
            c[get_sum(i)] += 1
        
        res = 0
        max_value = c.most_common(1)[0][1]
        for k,v in c.items():
            if max_value == v:
                res += 1
        return res


if __name__ == "__main__":
    print(Solution().countLargestGroup(24))